package com.zzy.msg;

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/message")
public class DemoController {
    private final MessagePublisher publisher;

    public DemoController(MessagePublisher publisher) {
        this.publisher = publisher;
    }

    @PostMapping
    public String sendMessage(@RequestParam String msg, @RequestParam(defaultValue = "testChannel") String channel) {
        publisher.publish(channel, msg);
        return "Message sent to channel: " + channel;
    }
}